import request from '@/utils/request'
import type { 
  ApiResponse, 
  UserInfo, 
  UserStats,
  PageParams,
  PageResult,
  Post
} from '@/types'

// 用户相关API
export const userApi = {
  // 获取用户信息（公开信息）
  getUserInfo: (id: number): Promise<ApiResponse<UserInfo>> => {
    return request.get(`/users/${id}`)
  },

  // 更新用户信息
  updateUserInfo: (id: number, data: Partial<UserInfo>): Promise<ApiResponse<UserInfo>> => {
    return request.put(`/users/${id}`, data)
  },

  // 获取用户文章列表
  getUserPosts: (id: number, params?: PageParams): Promise<ApiResponse<PageResult<Post>>> => {
    return request.get(`/users/${id}/posts`, { params })
  },

  // 更新用户头像
  updateAvatar: (userId: number, avatar: string): Promise<ApiResponse<string>> => {
    return request.put(`/users/${userId}/avatar`, { avatar })
  },

  // 获取用户统计数据
  getUserStats: (id: number, params?: PageParams): Promise<ApiResponse<UserStats>> => {
    return request.get(`/users/${id}/stats`, { params })
  }
}